﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CampaignWP7.Base;
using cocos2d;
using Microsoft.Xna.Framework;


namespace CampaignWP7
{
    public class WolfEmitter:DynamicsEmitter
    {
        public float EmitTime { get; set; }
        public float Strength { get; set; }
        static private int BornWolfCount = 0;
        private Random rnd;

        public WolfEmitter()
        {
            Reset();
            Enable = false;
        }

        public override void Emit(float dt)
        {
            if (!Enable) return;

            Counter += dt;
            EmitTime += dt;
            if (Counter > DelayTime)
            {
                Counter = 0;
                //
                Wolf wolf;
                if (BossAppear())
                {
                    GameLayer.m_bBossAppear = true;
                    GameStatusManager.instance.SetPlayStatus(GamePlayStatus.GAMEPLAYSTATUS_BOSS);
                    BornWolfCount++;
                }
                else
                {
                    if (NeedBornSpicialWolf())
                    {
                        int rndtype = rnd.Next((int)SPWolfType.SPWOLF_NUM);
                        wolf = SpicialWolfFactory.CreateSpicalWolf((SPWolfType)rndtype);
                    }
                    else
                    {
                        wolf = new Wolf(1);
                    }
                    BornWolfCount++;
                    wolf.position = new CCPoint(position.x, position.y);
                    wolf.PlayWalkAnimation();
                    wolf.Velocity = new Vector2(0, 0);
                    wolf.Acceleration = DynamicsObj.Gravity * -1;
                    wolf.userData = 2.0f;
                    //
                    DynamicMgr.Instance().AddChild(wolf);
                    //
                    float rndX = rnd.Next(GameLayerLayout.WolfWalkToJumpMinLengh, GameLayerLayout.WolfWalkToJumpMaxLengh);
                    CCPoint pos = new CCPoint(position.x - rndX, position.y);
                    wolf.PlayMoveToJump(Strength, pos);
                }
            }
        }
        //
        public override void Reset()
        {
            DelayTime = 1;
            Strength = 4;
            Direction = new Vector2(0, 0);
            //
            rnd = new Random();
            //
            Counter = 0;
            EmitTime = 0;
        }

        private bool NeedBornSpicialWolf()
        {
            int bornWolfID = BornWolfCount + 1;
            if (bornWolfID%10 == 0)
            {
                return true;
            }
            return false;
        }

        private bool BossAppear()
        {
            int bornWolfID = BornWolfCount + 1;
            if (bornWolfID % 20 == 0)
            {
                return true;
            }
            return false;
        }
    }
}
